﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using AdvanceLib;
using AdvanceLib.ScriptCore;

namespace ACompiler.SystemCommands
{
    public class CompileAndOutput : SystemCommand, IHelpEntity
    {
        #region SystemCommand Member
        public override string Name
        {
            get { return "compile"; }
        }
        public override int ExpectedParameters
        {
            get { return 3; }
        }
        public override void Execute(ScriptHost host, string[] parameters)
        {
            FileStream romStream = new FileStream(parameters[1], FileMode.Open);
            host.ROMStream = romStream;

            string source = File.ReadAllText(parameters[0], Encoding.Default);

            Program.script = host.CompileScript(source);
            Program.PrintSuccess();
        }
        public override bool DebugParameter(int paramIndex, string paramValue)
        {
            switch (paramIndex)
            {
                case 0:
                case 1:
                    return File.Exists(paramValue);
                case 2:
                    return paramValue == "-output";
            }
            return false;
        }
        #endregion

        #region IHelpEntity Member
        public string GetParameterString()
        {
            return "$fileName $ROM -output";
        }
        public string GetDescription()
        {
            return "Used to compile a script and output pointers.";
        }
        #endregion
    }
}
